package com.spring.theory.bean.lifeCycle;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

@Slf4j
public class Bean1 implements InitializingBean, DisposableBean {

    public Bean1() {
        log.info("Bean1构造");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("spring内置初始化 Bean1 init");
    }

    @PostConstruct
    public void init2() {
        log.info("@PostConstruct 注解初始化 Bean1 ");
    }

    public void init() {
        log.info("@Bean注解的initMethod自定义初始化 Bean1 init");
    }

    @Override
    public void destroy() throws Exception {
        log.info("spring内置销毁 Bean1 init");
    }

    @PreDestroy
    public void destroy2() {
        log.info("@PreDestroy 注解销毁 bean2;销毁前...");
    }

    public void destroy1() {
        log.info("@Bean注解的destroyMethod自定义销毁 Bean1 init");
    }

}
